//写一个泛型类，让你求一个数组当中的最大值
class Person implements Comparable<Person> {

    @Override
    public int compareTo(Person o) {
        return 0;
    }
}
    class Alg<T extends Comparable<T>>{
        public T findMaxVal(T[] array){
            T max = array[0];
            for (int i = 1; i <array.length ; i++) {
                if (array[i].compareTo(max)> 0){
                    max = array[i];
                }
            }
            return max;
        }
    }
//泛型方法
class Alg2 {
    public <T extends Comparable<T>> T findMaxVal(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}
    class Alg3{
        public static <T extends Comparable<T>> T findMaxVal(T[] array){
            T max = array[0];
            for (int i = 1; i <array.length ; i++) {
                if (array[i].compareTo(max)> 0){
                    max = array[i];
                }
            }
            return max;
        }
    }
public class MyArray<T> {
    public Object[] array = new Object[10];

    public void setValue(int pos,T val){
        array[pos] = val;
    }
    public T getValue(int pos){
        return (T) array[pos];
    }
    public static void main1(String[] args) {
        MyArray<String> myArray = new MyArray<>();

        //裸类型
        MyArray myArray1 = new MyArray();
        myArray1.setValue(0,1);
    }
    //想存放指定元素
    public static void main2(String[] args) {
        MyArray<String> myArray = new MyArray<>();
        myArray.setValue(0,"hi");
        myArray.setValue(1,"ho");
        myArray.setValue(2,"hp");

        String str = myArray.getValue(2);
        System.out.println(str);

        MyArray<Integer> myArray1 = new MyArray<>();
        myArray1.setValue(0,11);
        myArray1.setValue(1,22);
        int val = myArray1.getValue(0);
        System.out.println(val);

        MyArray<Person> myArray2 = new MyArray<>();

    }

    public static void main3(String[] args) {
        Integer[] array = {1,2,3,4,5};
        System.out.println(Alg3.findMaxVal(array));
        System.out.println(Alg3.<Integer>findMaxVal(array));
    }

    public static void main4(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,2,3,4,5};
        alg2.findMaxVal(array);
        alg2.<Integer>findMaxVal(array);
    }

    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,5};
        Alg<Integer> alg = new Alg<>();
        System.out.println(alg.findMaxVal(array));

        Alg<Person> alg1 = new Alg<>();
    }
}



